package com.itheima.controller;

import com.itheima.entity.PmsBrand;
import com.itheima.entity.PmsProductAttributeCategory;
import com.itheima.entity.PmsProductCategory;
import com.itheima.entity.vo.PmsProductAttributeVo;
import com.itheima.entity.vo.PmsProductVo;
import com.itheima.jsonresult.JsonResult;
import com.itheima.service.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private PmsProductCategoryService productCategoryService;

    @Autowired
    private PmsBrandService brandService;

    @Autowired
    private PmsProductAttributeCategoryService productAttributeCategoryService;

    @Autowired
    private PmsProductAttributeService productAttributeService;

    @Autowired
    private PmsProductService productService;


    //productCategory
    /**
     * 商品分类列表
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "分类名称",required = true,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页数",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize",value = "总页数",required = true,dataType = "Integer"),
    })
    @ApiOperation(value = "商品分类列表")
    @GetMapping("/getproductCategoryList")
    public JsonResult getProductCategoryList(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return productCategoryService.getProductCategoryList(name, page, pageSize);
    }

    /**
     * 添加商品分类
     * @param productCategory
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productCategory",value = "商品分类信息",required = true,dataType = "Json"),
    })
    @ApiOperation(value = "添加商品分类")
    @PostMapping("/addProductCategory")
    public JsonResult addProductCategory(@RequestBody PmsProductCategory productCategory){
        return productCategoryService.addProductCategory(productCategory);
    }


    //brand
    /**
     * 品牌列表
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "分类名称",required = true,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页数",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize",value = "总页数",required = true,dataType = "Integer"),
    })
    @ApiOperation(value = "品牌列表 ")
    @GetMapping("/getBrandList")
    public JsonResult getBrandList(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return brandService.getBrandList(name, page, pageSize);
    }

    /**
     * 添加品牌
     * @param brand
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "brand",value = "品牌信息",required = true,dataType = "Json"),
    })
    @ApiOperation(value = "添加品牌")
    @PostMapping("/addBrand")
    public JsonResult addBrand(@RequestBody PmsBrand brand){
        return brandService.addBrand(brand);
    }


    //productAttributeCategory
    /**
     * 商品属性分类列表
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "分类名称",required = true,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页数",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize",value = "总页数",required = true,dataType = "Integer"),
    })
    @ApiOperation(value = "商品属性分类列表")
    @GetMapping("/getProductAttributeCategoryList")
    public JsonResult getProductAttributeCategoryList(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return productAttributeCategoryService.getProductAttributeCategoryList(name, page, pageSize);
    }

    /**
     * 添加商品属性分类
     * @param productAttributeCategory
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "brand",value = "品牌信息",required = true,dataType = "Json"),
    })
    @ApiOperation(value = "添加商品属性分类")
    @PostMapping("/addproductAttributeCategory")
    public JsonResult addproductAttributeCategory(@RequestBody PmsProductAttributeCategory productAttributeCategory){
        return productAttributeCategoryService.addproductAttributeCategory(productAttributeCategory);
    }

    /**
     * 商品属性分类下拉列表
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productAttributeCategoryId",value = "商品属性分类id",required = true,dataType = "String"),
    })
    @ApiOperation(value = "商品属性分类下拉列表")
    @GetMapping("/pullProductAttributeCategoryList")
    public JsonResult pullProductAttributeCategoryList(String productAttributeCategoryId){
        return productAttributeCategoryService.pullProductAttributeCategoryList(productAttributeCategoryId);
    }


    //productAttribute
    /**
     * 商品规格列表
     * @param type
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "属性的类型",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "page",value = "页数",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize",value = "总页数",required = true,dataType = "Integer"),
    })
    @ApiOperation(value = "商品规格列表")
    @GetMapping("/getPmsProductAttributeList")
    public JsonResult getPmsProductAttributeList(Integer type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return productAttributeService.getPmsProductAttributeList(type, page, pageSize);
    }

    /**
     * 添加商品属性
     * @param productAttributeDto
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productAttribute",value = "商品属性信息",required = true,dataType = "Json"),
    })
    @ApiOperation(value = "添加添加商品属性")
    @PostMapping("/addProductAttribute")
    public JsonResult addProductAttribute(@RequestBody PmsProductAttributeVo productAttributeDto){
        return productAttributeService.addProductAttribute(productAttributeDto);
    }


    //product
    /**
     * 添加商品信息
     * @param productVo
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productVo",value = "商品信息",required = true,dataType = "Json"),
    })
    @ApiOperation(value = "添加商品信息")
    @PostMapping("/addProduct")
    public JsonResult addProduct(@RequestBody PmsProductVo productVo){
        return productService.addProduct(productVo);
    }



}
